package org.example.order.controller;

import org.example.order.service.OrderService;
import org.example.order.service.dto.OrderDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrderController {
    private OrderService orderService;

    public OrderController(@Autowired OrderService orderService) {
        this.orderService = orderService;
    }

    @GetMapping(value = "/{orderId}")
    public Result getOrder(@PathVariable("orderId") String orderId, @RequestParam(value = "repeat", required = false, defaultValue = "5") int repeats) {
        OrderDTO orderDTO = orderService.getOrder(orderId);
        for (int i = 1; i < repeats; i++) {
            orderService.getOrder(orderId);
        }
        return Result.success(orderDTO);
//        ModelAndView mav = new ModelAndView();
//        mav.addObject(Result.success(orderDTO));
//        mav.setStatus(HttpStatus.OK);
//        mav.setView(new MappingJackson2JsonView());
//        return mav;
    }
}
